<!DOCTYPE html>
<html lang="en">
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script src="/js/vue/vue.min.js"></script>
    <script src="/js/layer/layer.js" charset="utf-8"></script>
</head>
<body>
<section id="container">
<#include "sider.ftl">
    <section id="main-content">
        <section class="wrapper">
            <div class="row">
                <div class="col-lg-12" id="app">
                    <section class="panel">
                        <header class="panel-heading">
                            添加套餐
                        </header>
                        <div class="panel-body" >
                            <div class="form">
                                <form class="cmxform form-horizontal" id="addComboForm">
                                    <div class="form-group ">
                                        <label for="insurcateName" class="control-label col-lg-3">套餐名称</label>
                                        <div class="col-lg-6">
                                            <input class=" form-control" id="insurname" name="insurname" type="text">
                                        </div>
                                    </div>

                                    <div class="form-group ">
                                        <label for="maxinsur" class="control-label col-lg-3">保险类别</label>
                                            <table>
                                                <tr v-for="(item,index) in result">
                                                    <td><input type="checkbox" class="inputBox" :value="item.iuuid" name="iuuid"/>{{item.insurname}}</td>
                                                </tr>
                                            </table>
                                    </div>
                                    <div class="form-group ">
                                        <label for="maxinsur" class="control-label col-lg-3">套餐优惠率</label>
                                        <div class="col-lg-6">
                                            <input class=" form-control" id="maxinsur" name="maxinsur" type="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-lg-offset-3 col-lg-6">
                                            <button class="btn btn-primary" type="button" id="saveBtn">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
            </div>
        </section>
    <#include "/foot.html"><#--引入底部-->
    </section>
</section>
</body>
</html>
   <script>
       var app = new Vue({
           el: "#app",
           data: {
               result: []
           }
       });

       $(function () {
           $.ajax({
               type:"POST",
               dataType:"json",
               url:"/insurcate/getAllUseableInsurcate.do",
               success:function (data) {
                   app.result = data.allUseableInsurcate;
               }

           })
       });

       $("#saveBtn").click(function () {
           var checkedNum = $("input[type='checkbox']:checked[class='inputBox']").length;
           alert(checkedNum);
           if (checkedNum == 0) {
               layer.msg("请至少选择一项!", {icon: 6});
               return false;
           }
           var iuuIdList = new Array();
           //给每一个选中的标签都绑定一个方法
           $("input[type='checkbox']:checked[class='inputBox']").each(function () {
               //将标签的值放入数组中
               iuuIdList.push($(this).val());//此处添加不能使用add  add不是一个function
           });
           addInsurComb(iuuIdList);
           layer.open(window.location="/comb/toComboList.do");
       });

       var addInsurComb=function(iuuIdList){
           $.ajax({
               type:"POST",
               dataType:"JSON",
               url:"/comb/addComb.do",
               data:{
                   iuuIdList:iuuIdList,
                   insuratio:$("#maxinsur").val(),
                   insurname:$("#insurname").val()
               },
               success:function (data){
                alert("成功");
               }
           });
       }


   </script>